package com.js.blog.exception;

import com.js.blog.result.ResponseEntity;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yanglin
 * @create 2024-02-28 16:01 星期三
 * description:  全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    
    /**
     * 全局异常处理
     */
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResponseEntity error(Exception e){
        e.printStackTrace();
        return ResponseEntity.fail();
    }


    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public ResponseEntity error(BusinessException businessException){
        businessException.printStackTrace();
        return new ResponseEntity(businessException.getErrorCode().getCode(),businessException.getErrorCode().getMessage(),null);
    }
    
}
